<?php
session_save_path('../../sessions');
session_start();
        

// If we didn't come from the .php, send back to login routing page
if( !isset($_SESSION['homeIdToModify']) )
    header("location:../../admin_manageUsers.php");
else {
    
    // Connect to our database
    include("../dbconnection.php");
    
    
    // Clean our input    
    $city = mysql_real_escape_string($_POST["city"]);
    $country = mysql_real_escape_string($_POST["country"]);
    $district = mysql_real_escape_string($_POST["district"]);
    $zone = mysql_real_escape_string($_POST["zone"]);
    $postalCode = mysql_real_escape_string($_POST["postalcode"]);
    $lotSize = mysql_real_escape_string($_POST["lotsize"]);
    $propertyType = mysql_real_escape_string($_POST["propertyType"]);
    $yearBuilt = mysql_real_escape_string($_POST["yearbuilt"]);
    $heating = mysql_real_escape_string($_POST["heating"]);
    $cooling = mysql_real_escape_string($_POST["cooling"]);
    $parking = mysql_real_escape_string($_POST["parking"]);
    $garage = mysql_real_escape_string($_POST["garage"]);
    $driveway = mysql_real_escape_string($_POST["driveway"]);
    $neighborhood = mysql_real_escape_string($_POST["neighborhood"]);
    $recentImprovements = mysql_real_escape_string(rtrim(trim($_POST["recentImprovements"])));
    $evaluatedPrice = mysql_real_escape_string($_POST["evaluatedPrice"]);
    $propertyTaxes = mysql_real_escape_string($_POST["propertyTaxes"]);
    $utilityCost = mysql_real_escape_string($_POST["utilityCost"]);
    $price = mysql_real_escape_string($_POST["price"]);
    $comments = mysql_real_escape_string(rtrim(trim($_POST["comments"])));
    
    
    // Update home table query
    $updateHome_query = "UPDATE $TABLE_HOME 
    SET $TABLE_HOME_CITY = '$city', $TABLE_HOME_COUNTRY = '$country', $TABLE_HOME_DISTRICT = '$district',    
    $TABLE_HOME_ZONE = '$zone', $TABLE_HOME_POSTALCODE = '$postalCode', $TABLE_HOME_LOTSIZE = $lotSize,     
    $TABLE_HOME_PROPERTYTYPE = $propertyType, $TABLE_HOME_YEARBUILT = $yearBuilt, $TABLE_HOME_HEATING = $heating,
    $TABLE_HOME_COOLING = $cooling, $TABLE_HOME_PARKING = $parking, $TABLE_HOME_GARAGE = $garage,      
    $TABLE_HOME_DRIVEWAY = $driveway, $TABLE_HOME_NEIGHBOURHOOD = '$neighborhood', $TABLE_HOME_IMPROVEMENTS = '$recentImprovements',
    $TABLE_HOME_EVALUATION = $evaluatedPrice, $TABLE_HOME_TAXES = $propertyTaxes, $TABLE_HOME_UTILITYCOST = $utilityCost,
    $TABLE_HOME_PRICE = $price, $TABLE_HOME_COMMENTS = '$comments' 
    WHERE $TABLE_HOME_HOMEID = ".$_SESSION['homeIdToModify'];
    
  
    // Execute the user update query
    mysql_query($updateHome_query);
    // Close the connection
    mysql_close();
    
   
    // Set a small message to let the admin know the update was successful
    $_SESSION['updateSuccess'] = "Home with home ID ".$_SESSION['homeIdToModify']." was updated successfully.";
    
    // Make sure the home ID are unset, just in case.
    unset($_SESSION['homeIdToModify']);


    // Go back to where we were
    header("location:../../admin_manageListings.php");
    
}